package main

import (
	"gomicro/microGrpc/grpcClient/controller"
	_ "gomicro/microGrpc/grpcClient/controller"
	//"gowork/microGrpc/grpcMessage"
	"log"

	"github.com/kataras/iris/v12"
	"github.com/kataras/iris/v12/mvc"
	"github.com/micro/go-micro/v2"
	// "github.com/micro/go-micro/client"
	// "github.com/micro/go-micro/client/selector"

	"github.com/micro/go-micro/v2/web"
	"github.com/micro/go-plugins/registry/etcdv3/v2"
)

func main() {

	// grpcService := grpc.NewService(
	// 	micro.Name("go.micro.api.student"),
	// )

	// grpcService.Init()

	etcdRegistry := etcdv3.NewRegistry()

	microService := micro.NewService(
		//micro.Selector(selector.RoundRobin()),
		micro.Registry(etcdRegistry),
	)

	service := web.NewService(
		web.Name("go.micro.api.student"),
		web.Registry(etcdRegistry),
	)

	microService.Init()

	service.Init()
	
	// getService , sErr := etcdRegistry.GetService("student_micro_service")
	// if sErr != nil{
	// 	log.Fatal(sErr)
	// }
	// netx := selector.RoundRobin(getService)
	// note, err := netx()
	// if err != nil {
	// 	log.Fatal(note)
	// }

	// controller.Cli = webMessage.NewStudentService(note.Address, client.DefaultClient)

	app := iris.New()
	mvc.New(app).Handle(new(controller.StudentMicroController))
	app.Run(iris.Addr(":0002"))

	service.Handle("/", app)

	if err := service.Run(); err != nil {
		log.Fatal(err)
	}

}

/*
自定义负载均衡：创建结构体，实现Selector接口，初始化 //micro.Selector(&结构体实例),
*/